import { 
  selectOrderStatusCountbyDate, 
  selectKangNingOrderStatusList, 
  selectCustomerOrders, 
  selectKPI, 
  selectPalletFlow,
  selectStockStatistics,
  selectOrderStatistics 
} from '@/services/corelle/orderAnalysis';

//import prompt from '@/components/Prompt';
import { getPageSize } from '@/utils/common';

export default {
  namespace: 'orderAnalysis',

  state: {
    OrderStatusCountbyDate: {},
    OrderStatusList: {},
    CustomerOrders: {},
    KPI: {},
    selectPalletFlow: {},
    selectStockStatistics:{}
  },

  effects: {
    // 一、 仓库订单仪表盘
    *selectOrderStatusCountbyDate({ payload, callback }, { call, put }) {
      const response = yield call(selectOrderStatusCountbyDate, payload);
      const {
        code,
        data
      } = response;

      yield put({
        type: 'saveAllValus',
        payload: {
          OrderStatusCountbyDate: data,
        },
      });
      callback && callback(data);
    },
    //二、康宁订单状态表按时间点  -- 订单状态
    *selectKangNingOrderStatusList({ payload, callback }, { call, put }) {
      const response = yield call(selectKangNingOrderStatusList, payload);
      const { code, data } = response;
      // if (code !== 0) return;
      yield put({
        type: 'saveAllValus',
        payload: {
          OrderStatusList: data,
        },
      });
      callback && callback(data);
    },
    //三、康宁订单 客户订单 统计  --出货订单分布

    *selectCustomerOrders({ payload, callback }, { call, put }) {
      const response = yield call(selectCustomerOrders, payload);
      const { data, code } = response;
      yield put({
        type: 'saveAllValus',
        payload: {
          CustomerOrders: data,
        },
      });
      callback && callback(data);
    },
    //四、康宁订单 KPI 统计  --KPI

    *selectKPI({ payload, callback }, { call, put }) {
      const response = yield call(selectKPI, payload);
      const { data, code } = response;
      yield put({
        type: 'saveAllValus',
        payload: {
          KPI: data,
        },
      });
      callback && callback(data);
    },
    // 五.查看OCS进出托盘流量
    *selectPalletFlow({ callback }, { call, put }) {
      const response = yield call(selectPalletFlow);
      const { data, code } = response;
      yield put({
        type: 'saveAllValus',
        payload: {
          selectPalletFlow: data,
        },
      });
      callback && callback(data);
    },

    // 五.查看OCS仓库统计
    *selectStockStatistics({ callback }, { call, put }) {
      const response = yield call(selectStockStatistics);
      const { data, code } = response;
      yield put({
        type: 'saveAllValus',
        payload: {
          selectStockStatistics: data,
        },
      });
      callback && callback(data);
    },
   // 
   *selectOrderStatistics({ callback }, { call, put }) {
    const response = yield call(selectOrderStatistics);
    const { data, code } = response;
    yield put({
      type: 'saveAllValus',
      payload: {
        selectOrderStatistics: data,
      },
    });
    callback && callback(data);
  },
    /**
         * 设置表单参数
         */
    *allValus({ payload }, { _, put }) {
      yield put({
        type: 'saveAllValus',
        payload,
      });
    },
  },

  reducers: {
    //设置表单参数
    saveAllValus(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
    detail(state, { payload }) {
      let param = '';
      for (let k in payload) {
        param = k;
      }
      return {
        ...state,
        [param]: { ...state[param], ...payload[param] },
      };
    },
    list(state, { payload }) {
      let param = '';
      for (let k in payload) {
        param = k;
      }
      return {
        ...state,
        [param]: { ...payload[param] },
      };
    },
  },
};
